package cn.actoncode.boot.module.ai.controller.app.ability;

import cn.actoncode.boot.framework.common.pojo.CommonResult;
import cn.actoncode.boot.framework.security.core.annotations.PreAuthenticated;
import cn.actoncode.boot.framework.web.core.util.WebFrameworkUtils;
import cn.actoncode.boot.module.ai.controller.app.ability.vo.AbilityRespVO;
import cn.actoncode.boot.module.ai.controller.app.ability.vo.AbilityUsedRecordRespVO;
import cn.actoncode.boot.module.ai.convert.intelligentagent.AbilityConvert;
import cn.actoncode.boot.module.ai.convert.intelligentagent.AbilityUsedRecordConvert;
import cn.actoncode.boot.module.ai.dal.dataobject.ability.AbilityDO;
import cn.actoncode.boot.module.ai.dal.dataobject.ability.AbilityUsedRecordDO;
import cn.actoncode.boot.module.ai.service.ability.AbilityService;
import cn.actoncode.boot.module.ai.service.ability.AbilityUsedRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.actoncode.boot.framework.common.pojo.CommonResult.success;

@Tag(name = "能力 API")
@RestController
@RequestMapping("/ability")
@Slf4j
public class AbilityController {

	@Resource
	private AbilityService abilityService;

	@Resource
	private AbilityUsedRecordService abilityUsedRecordService;

	@GetMapping("/get")
	@Operation(summary = "获取能力")
	@Parameter(name = "type", description = "类型 1:产品需求 2:解决方案 3:思维导图 4:流程图", required = true, example = "1")
	@PreAuthenticated
	public CommonResult<AbilityRespVO> getAbilityList(@RequestParam("type") Integer type) {
		AbilityDO ability = abilityService.getAbility(type);
		return success(AbilityConvert.INSTANCE.convert(ability));
	}

	@GetMapping("/list")
	@Operation(summary = "获取能力列表")
	@PreAuthenticated
	public CommonResult<List<AbilityRespVO>> getAbilityList() {
		List<AbilityDO> abilityList = abilityService.getAbilityList();
		return success(AbilityConvert.INSTANCE.convertList(abilityList));
	}

	@GetMapping("/used-record/get")
	@Operation(summary = "获取能力使用记录")
	@Parameter(name = "id", description = "ID", required = true, example = "123")
	@PreAuthenticated
	public CommonResult<AbilityUsedRecordRespVO> getAbilityUsedRecord(@RequestParam("id") Long id) {
		AbilityUsedRecordDO abilityUsedRecord = abilityUsedRecordService.getAbilityUsedRecord(id);
		return success(AbilityUsedRecordConvert.INSTANCE.convert(abilityUsedRecord));
	}

	@GetMapping("/used-record/list")
	@Operation(summary = "获取能力使用记录列表")
	@PreAuthenticated
	public CommonResult<List<AbilityUsedRecordRespVO>> getAbilityUsedRecordList() {
		Long userId = WebFrameworkUtils.getLoginUserId();
		List<AbilityUsedRecordDO> abilityUsedRecordList = abilityUsedRecordService.getAbilityUsedRecordList(userId);
		return success(AbilityUsedRecordConvert.INSTANCE.convertList(abilityUsedRecordList));
	}
}
